<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>添加管理员</title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <meta name="author" content="yeshop Team" />
    <meta name="copyright" content="yeshop" />

    <% include("../inc/input_css.html"){}%>
    <style>
        label{
            width: 140px!important;
        }
    </style>

    <script type="text/javascript" src="${base}/res/js/jquery.js"></script>
    <script type="text/javascript">
        var setting = {
            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            },
            view: {
                dblClickExpand: false
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick: onClick,
                onCheck: onCheck
            },
            async: {
                enable: true,
                url:"${base}/shop/action/resourceTree?actionId=${action.id!}",
                autoParam:["id", "name=n", "level=lv"],
                otherParam:{"otherParam":"zTreeAsyncTest"}
            }
        };

        function onClick(e, treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            zTree.checkNode(treeNode, !treeNode.checked, null, true);
            return false;
        }

        function onCheck(e, treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
                nodes = zTree.getCheckedNodes(true),
                v = "";
            vid="";
            for (var i=0, l=nodes.length; i<l; i++) {
                v += nodes[i].name + ",";
                vid+=nodes[i].id + ',';
            }
            if (v.length > 0 ){
                v = v.substring(0, v.length-1);
                vid=vid.substring(0, vid.length-1);
            }
            var cityObj = $("#citySel");
            var resourceId=$("#resourceId");
            cityObj.attr("value", v);
            resourceId.attr("value",vid);
        }

        function showMenu() {
            var cityObj = $("#citySel");
            var cityOffset = $("#citySel").offset();
            $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
            $("body").bind("mousedown", onBodyDown);
        }
        function hideMenu() {
            $("#menuContent").fadeOut("fast");
            $("body").unbind("mousedown", onBodyDown);
        }
        function onBodyDown(event) {
            if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
                hideMenu();
            }
        }

        $(document).ready(function(){
            $.fn.zTree.init($("#treeDemo"), setting);
        });
    </script>

    <%
    var isAdd = false;
    var isEdit = false;
    if(isEmpty(action.id)){
    isAdd = true;
    }else{
    isEdit = true;
    }
    %>
</head>
<body>
<div class="ibox">
    <div class="ibox-title">
        <div class="pull-left mbx navbar_title">
            <span class="current">权限管理</span>
            <span class="line">/</span>
            <span class="current"><a href="/shop/action/list">动作管理</a></span><span class="line">/</span>
            <%if(isAdd){%>添加动作<%}else{%>编辑动作<%}%>
        </div>
    </div>
    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="padding-40">
                    <form class="form-horizontal form-validate" method="post" id="form" action="<%if(isAdd){%>${base}/shop/action/save<%}else{%>${base}/shop/action/update<%}%>">
                        <input type="hidden" name="action.id" value="${action.id!}" />
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span class="maroon">*</span>动作名称</label>
                            <div class="col-sm-3">
                                <input type="text" name="action.name" value="${action.name!}" class="form-control input-sm" required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span class="maroon">*</span>资源名称</label>
                            <div class="col-sm-3">
                                <input type="hidden" name="action.resourceId" id="resourceId" value="${action.resourceId!}"/>
                                <input type="text" name="" id="citySel" class="form-control input-sm" readonly value="${action.byResourceId.name!}" required="true" onclick="showMenu();"/>
                                <a id="menuBtn" href="#" onclick="showMenu(); return false;">选择</a></li>
                            </div>
                        </div>
                        <div class="form-group" style="margin-top: 24px">
                            <label class="col-sm-2 control-label "></label>
                            <div class="col-sm-4 col-sm-offset-0 ">
                                <button class="hive-btn-cancle" id="btn_cancle" type="button" onclick="history.back()">&nbsp;取消&nbsp;</button>
                                <button class="hive-btn hive-btn-primary margin-left-8" type="submit">&nbsp;提交&nbsp;
                                </button>
                            </div>
                        </div>
                        <table class="input" id="showMenuContent" style="height: 300px;">
                            <tr>
                                <th style="background-color: white;border-bottom: aliceblue;">
                                    <div id="menuContent" class="menuContent" style="display:none; position: absolute;background: #f0f6e4;">
                                        <ul id="treeDemo" class="ztree" style="margin-top:0; width:242px; height: 300px;"></ul>
                                    </div>
                                </th>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>


    <% include("../inc/input_js.html"){}%>
<!-- 自定义js -->
<!--ZTREE DEMO-->
<!--<link rel="stylesheet" href="${base}/res/plugins/ztreev3/css/demo.css" type="text/css">-->
<link rel="stylesheet" href="${base}/res/plugins/ztreev3/css/zTreeStyle/zTreeStyle.css" type="text/css">

<script type="text/javascript" src="${base}/res/plugins/ztreev3/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${base}/res/plugins/ztreev3/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" src="${base}/res/plugins/ztreev3/js/jquery.ztree.exedit.js"></script>
</body>
</html>